//
// Created by LiuYou on 2021/8/20.
//

#include <exception>
#include "Semaphore.hpp"

Semaphore::Semaphore() {
    if (sem_init( &semaphore, 0, 0 ) != 0) {
        throw std::exception();
    }
}

Semaphore::~Semaphore() {
    sem_destroy( &semaphore );
}

bool Semaphore::wait() {
    return sem_wait( &semaphore ) == 0;
}

bool Semaphore::post() {
    return sem_post( &semaphore ) == 0;
}
